<template>
	<view class="flex-col page">
		<canvas id="qrcode" canvas-id="qrcode" style="width: 200px;height: 200px;margin: 30rpx auto;"></canvas>
	</view>
</template>

<script setup>
	import UQRCode from '../../utils/uqrcode.js';
	import {
		onShow,
		onLoad
	} from "@dcloudio/uni-app";
	import {
		onMounted,
		ref,
		reactive,
		getCurrentInstance
	} from "vue"
	const {
		proxy
	} = getCurrentInstance()
	const getCurrent = getCurrentInstance()
	onLoad((option) => {
		data.value.order_id = option.id
		data.value.index = option.index
		codeInit()
		getDate()
	})
	onShow(() => {
		codeInit()
	})
	let data = ref({
		order_id: '',
		index: '',
		content:''
	})
	const codeInit = () => {
		var qr = new UQRCode();
		// 设置二维码内容
		qr.data = data.value.order_id;
		// 设置二维码大小，必须与canvas设置的宽高一致
		qr.size = 200;
		// 调用制作二维码方法
		qr.make();
		// 获取canvas元素
		// 设置uQRCode实例的canvas上下文
		qr.canvasContext = uni.createCanvasContext('qrcode', getCurrent)
		// 调用绘制方法将二维码图案绘制到canvas上
		qr.drawCanvas()
		console.log(qr,"qr");
	}
	const getDate = () => {
		proxy.$req.requestPOST(proxy.$api.orderInfo.getDtail, {
			user_id: uni.getStorageSync('user_id') | '',
			id: data.value.order_id,
		}).then(res => {
			if (res.code == 1) {
				// console.log(res);
				data.value.content = res.data.list
			}
		})
	}
	const toStatus=(t1,t2)=>{
		let title
		if (t1==0&&t2==3) {
			title='确定要取消订单吗？'
		} else if (t1==0&&t2==2) {
			title='确定要删除订单吗？'
		} else if (t1==3&&t2==1) {
			title='确定已邮寄吗？'
		}
		uni.showModal({
			title: '提示',
			content:title ,
			success: function(res) {
				if (res.confirm) {
					proxy.$req.requestPOST(proxy.$api.orderInfo.edit, {
						id: data.value.order_id,
						user_id: uni.getStorageSync('user_id') | '',
						order_status: t1,
						type: t2,
					}).then(res => {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						if (res.code == 1) {
							setTimeout(() => {
								getDate()
							}, 1000)
						}
					})
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		})
	}
	const toPay = () => {
		uni.navigateTo({
			url: '/pages/payment/payment?order=' + data.value.content.id + '&price=' + data.value.content.price+'&endtime='+data.value.content.endtime
		})
		// uni.navigateTo({
		// 	url:'/pages/payment/payment?id='+data.value.order_id+"type=3"
		// })
	}
	const toLoat = () => {
		uni.openLocation({
			latitude: data.value.content.lat * 1,
			longitude: data.value.content.lng * 1,
			complete: function(res) {
				console.log('complete', res);
			}
		});
	}
	const toPhone = (type) => {
		uni.makePhoneCall({
			phoneNumber: type == 1 ? data.value.content.shop_mobile : data.value.content.courier_phone //仅为示例
		});
	}
	const toEvaluate = () => {
		uni.navigateTo({
			url: '/pages/evaluate/evaluate?order_id=' + data.value.order_id + '&shop_id=' + data.value.content
				.shop_id
		})
	}

	const toRefund = () => {
		uni.navigateTo({
			url: '/pages/applyFor/applyFor?order_id=' + data.value.order_id
		})
	}
	const toSchedule = () => {
		uni.navigateTo({
			url: '/pages/speed/speed?order_refund_id=' + v.order_refund_id
		})
	}
</script>

<style scoped lang="scss">

	.page {
		background-color: #ffffff;
		width: 100%;
		// overflow-y: auto;
		overflow-x: hidden;
		height: 100%;

	
	}
</style>